package com.example.entity;

import java.io.Serializable;

public class Request<T extends Payload> implements Serializable {
    private static final long serialVersionUID = 6101112170101524540L;
    /**
     * 元数据
     */
    private Metadata metadata;
    /**
     * 数据
     */
    private T payload;
    /**
     * 服务内部处理字段
     */
    private Departure departure;

    public Metadata getMetadata() {
        return metadata;
    }

    public void setMetadata(Metadata metadata) {
        this.metadata = metadata;
    }

    public T getPayload() {
        return payload;
    }

    public void setPayload(T payload) {
        this.payload = payload;
    }

    public Departure getDeparture() {
        return departure;
    }

    public void setDeparture(Departure departure) {
        this.departure = departure;
    }

    public boolean isValid() {
        if (payload != null) {
           Payload.Command command = payload.getCommand();
            if (command != null) {
                return (command.getCode() != null) && (command.getCode() > 0L) &&
                        (command.getSubCode() != null) && (command.getSubCode() >= 0);
            }
        }
        return false;
    }

    public static class DefaultRequest extends Request<Payload> {
        private static final long serialVersionUID = -1597489950397874826L;
    }
}